<?php




class Test_ci_form_validation extends CI_Controller {

	public function __construct() {
		parent::__construct(); 
                // the tutorial shows this as 
                // parent::Controller();
                
                $this->load->helper(array('form','url'));
                $this->load->library('form_validation');
	}

	public function index() {
		//$this->load->view('placeholder_view');
                
                        $user_id = '2';
                
                        // get an object by ID
                        $user = $this->doctrine->em->find('ORM\Testing\User', $user_id);
                        //echo $user->getFirstName().' '.$user->getLastName().' is a real chill guy.<br />';

                        // get a related object
                        $article = $this->doctrine->em->find('Testing\Article', $user_id);
                        $user = $article->getUser();
                       //echo $user->getFirstName().' '.$user->getLastName().' thinks CodeIgniter + Doctrine is real slick. <br />';

                        // what happens when we try to get an object that doesn't exist?
                        $article = $this->doctrine->em->find('Testing\Article', 9001);
                        if(is_null($article))
                        {
                            // the "find" call returns NULL!
                            //echo 'Dude, that article number 9001 doesn\'t even exist yet.<br />';
                        }

                        // get an object by another field
                        
                        //$other_field = 'joel@joelverhagen.com';
                        $other_field = 'bobby@bobbybrown.com';
                        
                        $user = $this->doctrine->em->getRepository('ORM\Testing\User')->findOneBy(array('email' => $other_field));
                        //echo $user->getFirstName().' '.$user->getLastName().' is glad he isn\'t dealing with Symfony.<br />';
                        
                        echo "I am testing with " . $other_field . " to see if it is already in the db.</br>";
                        
                        //does not work:
                        //if (isset($user->getEmail())) {
                            
                        if (isset($user)) {
                            echo "User is set!";
                        } else {
                            echo "User is NOT set!";
                        }
                        
                        
                        //does not work if it is empty, generates error
                        //Fatal error: Call to a member function getEmail() on a non-object in /home/xxxjermxxx/dixieandtheninjas.net/hellounderscoreworld/applicationFolder/controllers/test_ci_form_validation.php on line 54
                        //if ($user->getEmail() === $other_field) {  
                        //    echo "We pulled this from the db: " . $user->getEmail() . ", alright!</br>";   
                        //} else {   
                        //    echo "Nothing retrieved from the db.</br>";   
                        //}
                              
                        
                


        }
}


